package com.bxl.netty.rpc.client;


import com.bxl.netty.rpc.client.common.register.CallBackRegister;
import com.bxl.netty.rpc.client.context.ClientContext;
import com.bxl.netty.rpc.client.context.ClientContextImpl;
import com.bxl.netty.rpc.common.future.CompletableFuture;
import com.bxl.netty.rpc.common.message.PackageMsg;

/**
 * <>
 *
 * @author baixl
 * @date 2021/2/24
 */
public class RpcClientAgent {
    private static ClientContext context;
    private static RpcClientFactory clientFactory;
    static{
        context = new ClientContextImpl();
        context.init();
        clientFactory = context.getClientFactory();
    }
    
    public static CompletableFuture sendMsg(PackageMsg packageMsg) {
        CompletableFuture cf = new CompletableFuture();
        CallBackRegister.register(packageMsg.getHeader().getRequestID(),cf);
        clientFactory.getClient("localhost").writeAndFlush(packageMsg);
        return cf;
    }

}
